﻿using System;
using System.Data;
using System.Runtime.InteropServices;
using System.Web;
using System.Web.SessionState;
using System.Collections;
using System.Web.UI.WebControls;
using DreamBuilder.DictionaryAccess;


namespace DreamBuilder.UI.UserControls
{
    public class ListHelper
    {

        public static void SetGridViewColumnStyle(CVoucherListItemInfo listItemInfo, DataControlField gridViewColumn)
        {
            int nWidth = listItemInfo.Width;
            gridViewColumn.ItemStyle.HorizontalAlign = ControlCommon.GetAlignStyle(listItemInfo.ArrangeType);
            gridViewColumn.HeaderStyle.Width = Unit.Percentage(nWidth);
            gridViewColumn.ItemStyle.Width = Unit.Percentage(nWidth);
            gridViewColumn.SortExpression = listItemInfo.TableCode + "__" + listItemInfo.FieldCode;
            gridViewColumn.Visible = listItemInfo.Show;
        }

        public static void SetGridViewColumnHeaderText(CVoucherListItemInfo listItemInfo, DataControlField gridViewColumn, SortData sortData)
        {
            if (listItemInfo.Show == true)
            {
                if (sortData.SortExpression != null && sortData.SortExpression == listItemInfo.TableCode + "__" + listItemInfo.FieldCode)
                {
                    string sort = sortData.Sort;
                    //string sImageUrl = HttpContext.Current.Request.ApplicationPath + "/Images/Grid/" + sort + ".gif";
                    ////string img = "<img Class = \"LT-imgSort\" src='" + sImageUrl + "' >";
                    //gridViewColumn.HeaderText = GetColumnItemResInfo(listItemInfo) + img;
                    //gridViewColumn.HeaderStyle.CssClass = "LT-table-sortheader-td";
                    gridViewColumn.HeaderText = GetColumnItemResInfo(listItemInfo);
                }
                else
                {
                    gridViewColumn.HeaderText = GetColumnItemResInfo(listItemInfo);
                    //gridViewColumn.HeaderStyle.CssClass = "LT-table-header-td";
                }
            }
        }

        private static string GetColumnItemResInfo(CVoucherListItemInfo listItemInfo)
        {
            FieldResDicInfo fieldResDicInfo = DictionaryAccessFacade.GetFieldResDicInfo(listItemInfo.TableCode, listItemInfo.FieldCode);
            if (fieldResDicInfo != null)
                return fieldResDicInfo.FieldDesc;
            return "";
        }
    }
}
